package com.example.demo2.controller;

import com.example.demo2.util.TransferPage;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.stage.Stage;

/**
 * @description This class is for user interaction between users and seat selection page
 * @version 2.0
 */


public class SeatController {
    @FXML
    private Button backButton;

    @FXML
    private Button confirmButton;

    @FXML
    private Button button11;

    @FXML
    private Button button12;

    @FXML
    private Button button13;

    @FXML
    private Button button14;

    @FXML
    private Button button21;

    @FXML
    private Button button22;

    @FXML
    private Button button23;

    @FXML
    private Button button24;

    @FXML
    private Button button31;

    @FXML
    private Button button32;

    @FXML
    private Button button33;

    @FXML
    private Button button34;

    @FXML
    private Button button41;

    @FXML
    private Button button42;

    @FXML
    private Button button43;

    @FXML
    private Button button44;

    @FXML
    private Button button51;

    @FXML
    private Button button52;

    @FXML
    private Button button53;

    @FXML
    private Button button54;

    @FXML
    private Button button61;

    @FXML
    private Button button62;

    @FXML
    private Button button63;

    @FXML
    private Button button64;

    @FXML
    private Button button71;

    @FXML
    private Button button72;

    @FXML
    private Button button73;

    @FXML
    private Button button74;

    @FXML
    private Button button81;

    @FXML
    private Button button82;

    @FXML
    private Button button83;
    @FXML
    private Button button84;

    @FXML
    protected void addColorAction11(ActionEvent event) {
        button11.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button11);

    }

    @FXML
    protected void addColorAction12(ActionEvent event) {
        button12.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button12);

    }

    @FXML
    protected void addColorAction13(ActionEvent event) {
        button13.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button13);

    }

    @FXML
    protected void addColorAction14(ActionEvent event) {
        button14.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button14);

    }

    @FXML
    protected void addColorAction21(ActionEvent event) {
        button21.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button21);

    }

    @FXML
    protected void addColorAction22(ActionEvent event) {
        button22.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button22);

    }

    @FXML
    protected void addColorAction23(ActionEvent event) {
        button23.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button23);

    }

    @FXML
    protected void addColorAction24(ActionEvent event) {
        button24.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button24);

    }

    @FXML
    protected void addColorAction31(ActionEvent event) {
        button31.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button31);

    }

    @FXML
    protected void addColorAction32(ActionEvent event) {
        button32.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button32);

    }

    @FXML
    protected void addColorAction33(ActionEvent event) {
        button33.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button33);
    }

    @FXML
    protected void addColorAction34(ActionEvent event) {
        button34.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button34);

    }

    @FXML
    protected void addColorAction41(ActionEvent event) {
        button41.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button41);

    }

    @FXML
    protected void addColorAction42(ActionEvent event) {
        button42.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button42);

    }

    @FXML
    protected void addColorAction43(ActionEvent event) {
        button43.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button43);

    }

    @FXML
    protected void addColorAction44(ActionEvent event) {
        button44.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button44);

    }

    @FXML
    protected void addColorAction51(ActionEvent event) {
        button51.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button51);

    }

    @FXML
    protected void addColorAction52(ActionEvent event) {
        button52.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button52);

    }

    @FXML
    protected void addColorAction53(ActionEvent event) {
        button53.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button53);

    }

    @FXML
    protected void addColorAction54(ActionEvent event) {
        button54.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button54);

    }

    @FXML
    protected void addColorAction61(ActionEvent event) {
        button61.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button61);

    }

    @FXML
    protected void addColorAction62(ActionEvent event) {
        button62.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button62);

    }

    @FXML
    protected void addColorAction63(ActionEvent event) {
        button63.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button63);

    }

    @FXML
    protected void addColorAction64(ActionEvent event) {
        button64.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button64);

    }

    @FXML
    protected void addColorAction71(ActionEvent event) {
        button71.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button71);

    }

    @FXML
    protected void addColorAction72(ActionEvent event) {
        button72.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button72);

    }

    @FXML
    protected void addColorAction73(ActionEvent event) {
        button73.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button73);

    }

    @FXML
    protected void addColorAction74(ActionEvent event) {
        button74.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button74);

    }

    @FXML
    protected void addColorAction81(ActionEvent event) {
        button81.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button81);

    }

    @FXML
    protected void addColorAction82(ActionEvent event) {
        button82.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button82);

    }

    @FXML
    protected void addColorAction83(ActionEvent event) {
        button83.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button83);

    }

    @FXML
    protected void addColorAction84(ActionEvent event) {
        button84.setStyle(
                "-fx-border-color: #EE1169;"  //#EE1169
                //#ffffff
        );
        changeSeatCondition("seat", button84);

    }

    protected static void changeSeatCondition(String seat, Button button){
        String filename = seat;
        String id = button.getText();
        String reversed = new String();
        if (button.getStyle() == "-fx-border-color: #EE1169;") {
            reversed = "true";
        }else{
            reversed = "false";
        }
        boolean vip = false;
        if (id == "0101" || id == "0102" || id == "0103" || id == "0104") vip = true;



        //写入
//        String data = String.format("{\n" +
//                "      \"id\" : \"%s\",\n" +
//                "      \"vip\" : %s,\n" +
//                "      \"reserved\" : %s\n" +
//                "    }", id, vip, reversed);
//        com.example.demo2.dao.JsonWriter.saveDataToFile(filename, data);
    }

    public void confirmController(ActionEvent event) {
        Stage primaryStage = (Stage) confirmButton.getScene().getWindow();
        primaryStage.hide();
        TransferPage.transfer("food", "Food and Seat Selector",615,566);
    }

    public void backController(ActionEvent event) {
        Stage primaryStage = (Stage) backButton.getScene().getWindow();
        primaryStage.hide();
        TransferPage.transfer("flight-info", "Fight Info",617,745);
    }
}
